#!/bin/sh

TOMCAT_HOME=/opt/tomcat_webserver
SRC_HOME=/workspace/juxingapps/src/webserver
EXT_BASE=/workspace/juxingapps/ext
EXT_HOME=$EXT_BASE/webserver

if [ ! -d "$SRC_HOME" ]
then
    echo "folder $SRC_HOME is not exist."
    exit 1
fi

cd $SRC_HOME

#update source
git pull origin
if [ $? != 0 ] 
then
    echo "fail to get source."
    exit 1
fi

#install
mvn clean package -Ptest
if [ $? != 0 ] 
then
    echo "fail to build source."
    exit 1
fi

#stop old process
$TOMCAT_HOME/bin/shutdown.sh

#del old folder
rm -rf $EXT_HOME
mkdir $EXT_HOME -p
cd $EXT_HOME
jar xvf $SRC_HOME/target/*.war

#start process
$TOMCAT_HOME/bin/startup.sh
if [ $? != 0 ] 
then
    echo "fail to start the server"
    exit 1
fi

